<?php

FILESAVER;

/**
 * Description of db
 *
 * @author adrian
 */
class Db {

    /**
     *
     * @var Db
     */
    private static $instance = null;

    /**
     *
     * @var array
     */
    private $config = array();
    
    public static function instance() {
        if (self::$instance === null)
            self::$instance = new Db();
        return self::$instance;
    }

    private function  __construct() {
        $this->config = System::config('database');
        self::connect();
    }

    public static function connect(){
        $mysql_handler = mysql_connect($this->config['server'], $this->config['username'], $this->config['password']);
        if( $mysql_handler ){
            mysql_select_db($this->config['database']);
        }
        else{
            throw new ExceptionSystem("Nie można uzyskać połączenia z bazą danych", 700);
        }
    }

}
?>
